import { getCurrentInstance } from 'vue';

export function useThrottle(cb: Function, duration: number) {
  let start = +new Date();
  return function () {
    let args = arguments;
    let context = getCurrentInstance();
    let now = +new Date();
    if (now - start >= duration) {
      cb.apply(context, args);
      start = now;
    }
  };
}
